/*
 * @Author: xiehangyun 
 * @Date: 2025-05-16 10:34:07 
 * @Last Modified by: xiehangyun
 * @Last Modified time: 2025-05-16 21:18:47
 */

import { observable, configure } from "mobx";
import customerServiceApi from './CustomerServiceApi'
import { HotlineItem, FAQItem } from './CustomerServiceApi'
configure({ enforceActions: "never" });

// 默认的客服热线数据
const defaultHotlines: HotlineItem[] = [
    {
        id: '1',
        number: '400-123-4567',
        description: '售前咨询 (9:00-18:00)'
    },
    {
        id: '2',
        number: '400-765-4321',
        description: '售后服务 (9:00-20:00)'
    },
    {
        id: '3',
        number: '010-12345678',
        description: '投诉建议 (9:00-18:00)'
    }
];

// 默认的常见问题数据
const defaultFAQs: FAQItem[] = [
    {
        id: '1',
        question: '如何修改我的订单信息？',
        answer: '您可以在"我的订单"页面中找到需要修改的订单，点击"订单详情"，然后选择"修改订单"选项进行修改。'
    },
    {
        id: '2',
        question: '设计完成后如何下载我的设计作品？',
        answer: '您可以在"我的设计"页面中找到您的设计作品，点击进入详情页后，点击右上角的"下载"按钮即可下载。'
    },
    {
        id: '3',
        question: '如何申请退款？',
        answer: '在订单详情页面，点击"申请退款"按钮，填写退款原因并提交申请。我们的客服人员会在1-3个工作日内处理您的退款申请。'
    }
];

const customerServiceStore = observable({
    
    hotlines: defaultHotlines,//客服热线列表
    faqs: defaultFAQs,//常见问题列表
    loading: false,//加载状态
    error: '',//错误信息
    
    //获取客服热线
    async getHotlines() {
        this.loading = true;
        try {
            const res = await customerServiceApi.getHotlines();
            this.hotlines = res.data || defaultHotlines;
            this.error = '';
        } catch (err) {
            this.error = err.message || '获取客服热线失败';
            this.hotlines = defaultHotlines;
        } finally {
            this.loading = false;
        }
    },
    
    //获取常见问题
    async getFAQs() {
        this.loading = true;
        try {
            const res = await customerServiceApi.getFAQs();
            this.faqs = res.data || defaultFAQs;
            this.error = '';
        } catch (err) {
            this.error = err.message || '获取常见问题失败';
            this.faqs = defaultFAQs;
        } finally {
            this.loading = false;
        }
    },
    
    //开始客服会话
    async startService(userId: string) {
        this.loading = true;
        try {
            await customerServiceApi.startCustomerService(userId);
            this.error = '';
        } catch (err) {
            this.error = err.message || '启动客服会话失败';
        } finally {
            this.loading = false;
        }
    }

}, {}, { deep: false });

export default customerServiceStore;